package Smallchangesys;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class SmallChangeSys {
    public static void main(String[] args) {
        boolean loop = true;
        Scanner scanner = new Scanner(System .in);
        String key = " " ;
        String details = "==========零钱通明细==========\n";
        double money = 0;
        double balance = 0;
        Date data = null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yy-MM-dd hh-mm");
        String note = " ";
        do{
            System.out.println("==========零钱通菜单==========");
            System.out.println("\t\t\t1.零钱通明细");
            System.out.println("\t\t\t2.收益入账");
            System.out.println("\t\t\t3.消     费");
            System.out.println("\t\t\t4.退     出");
            System.out.print("请选择(1-4)");
            key = scanner.next();
            switch (key) {
                case "1":
                    System.out.println(details);
                    break;
                case "2":
                    System.out.println("2.收益入账");
                    money = scanner.nextDouble();
                    if (money <= 0){
                        System.out.println("收益入账金额要大于0");
                        break;
                    }
                    balance += money;
                    data = new Date();
                    details += "\n收益入账：\t" + "+" + money + "\t" +
                            simpleDateFormat.format(data) + "\t" + balance;
                    break;
                case "3":
                    System.out.print("3.消费金额：");
                    money = scanner.nextDouble();
                    if(money > balance || money <= 0){
                        System.out.println("消费金额应在账户余额范围内！");
                        break;
                    }
                    System.out.print("消费说明：");
                    note = scanner.next();
                    balance -= money;
                    data = new Date();
                    details += "\n" + "消费记录：" + "\t" + note + "\t" + "-" + money + "\t" +
                            simpleDateFormat.format(data) + "\t" + balance;
                    break;
                case "4":
                    String choice = " ";
                    while (true) {
                        System.out.println("确定退出?y/n");
                        choice = scanner.next();
                        if ("y".equals(choice)) {
                            loop = false;
                            break;
                        } else if ("n".equals(choice)){
                            break;
                        }
                    }
                    break;
                default:
                    System.out.println("选择有误，请重新选择");
            }
        }while (loop);
        System.out.println("======退出零钱通=====");
    }
}